#ifndef _IIC_H
#define _IIC_H
#include "sys.h"
#define SCL_H         GPIOB->BSRR = GPIO_PIN_6
#define SCL_L         GPIOB->BRR  = GPIO_PIN_6
   
#define SDA_H         GPIOB->BSRR = GPIO_PIN_7
#define SDA_L         GPIOB->BRR  = GPIO_PIN_7

#define SCL_read      HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_6)
#define SDA_read      HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_7)

//#define  ON_CS()    {GPIO_ResetBits(GPIOA,GPIO_Pin_4);}//delay_us(1);
#define  ON_CS()    (HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_RESET));
//#define  OFF_CS()   {GPIO_SetBits(GPIOA,GPIO_Pin_4);}//delay_us(1);
#define  OFF_CS()	(HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET));

#define CCS811_Add  0x5A<<1
#define STATUS_REG 0x00
#define MEAS_MODE_REG 0x01
#define ALG_RESULT_DATA 0x02
#define ENV_DATA 0x05
#define NTC_REG 0x06
#define THRESHOLDS 0x10
#define BASELINE 0x11
#define HW_ID_REG 0x20
#define ERROR_ID_REG 0xE0
#define APP_START_REG 0xF4
#define SW_RESET 0xFF
#define CCS_811_ADDRESS 0x5A
#define GPIO_WAKE 0x5
#define DRIVE_MODE_IDLE 0x0
#define DRIVE_MODE_1SEC 0x10
#define DRIVE_MODE_10SEC 0x20
#define DRIVE_MODE_60SEC 0x30
#define INTERRUPT_DRIVEN 0x8
#define THRESHOLDS_ENABLED 0x4


void I2C_GPIO_Config(void);
u8 I2C_Start(void);
void I2C_SendACK(u8 i);
u8 I2C_WaitAck(void);
void I2C_SendByte(u8 dat);
u8 I2C_RecvByte(void);
void I2C_Stop(void);
u8 I2C_RecvByte_s(u8 address,u8* recdata,u8 recnum);
void I2C_SendByte_S(u8 SlaAdd, u8 *SendDat, u8 Send_Num);
u8 Single_WriteI2C_byte(u8 Slave_Address,u8 REG_Address,u8 data);
u8 Single_MWriteI2C_byte(u8 Slave_Address,u8 REG_Address,u8 const *data,u8 length);
u8 Single_ReadI2C(u8 Slave_Address,u8 REG_Address,u8 *REG_data,u8 length);
#endif
